using Assets.Scripts.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CircleBtnImg : MonoBehaviour
{
    public int number;
    public string desc;
    Color normalColor;
    Color highLightedColor;
    Image btnImage;
    public Image btnImgImage;
    Button btn;
    CircleBtnPanel circleBtn;
    ComponentManager currentWeapon;
    private void Awake()
    {

    }
    private void Start()
    {

    }
    public void Init(CircleBtnPanel circleBtn)
    {
        this.circleBtn = circleBtn;
        btnImage = GetComponent<Image>();
        btn = GetComponent<Button>();
        btnImage.alphaHitTestMinimumThreshold = 0.5f;
        btn.onClick.AddListener(OnClick);
        gameObject.SetActive(true);
    }
    public void OnEnable_(ComponentManager weapon, Color normalColor, Color highLightedColor)
    {
        this.normalColor = normalColor;
        this.highLightedColor = highLightedColor;
        gameObject.SetActive(true);
        currentWeapon = weapon;
        btnImgImage.sprite = currentWeapon.GetSprite();
        desc = currentWeapon.GetDesc();
    }
    public void OnDisable_()
    {
        gameObject.SetActive(false);
        btnImgImage.sprite = null;
        desc = "";
    }
    private void OnClick()
    {
        circleBtn.CircleSwitch(number);
    }
    public bool CheckIsHighed()
    {
        if (btnImage.IsRaycastLocationValid(Camera.main.WorldToScreenPoint(Input.mousePosition), Camera.main))
        {
            OnBtnHighLighted();
            return true;
        }
        else
        {
            OnBtnNormal();
            return false;
        }
    }
    private void OnBtnHighLighted()
    {
        btnImage.color = highLightedColor;
        circleBtn.ShowBtnDesc(currentWeapon.GetDesc());
    }
    private void OnBtnNormal()
    {
        btnImage.color = normalColor;
    }

}
